package com.nut.spp.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nut.spp.common.Result;
import com.nut.spp.entity.SysParam;
import com.nut.spp.mapper.SysParamMapper;
import com.nut.spp.service.SysParamService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.Set;

@Slf4j
@Service
public class SysParamServiceImpl implements SysParamService {

    @Autowired
    private SysParamMapper sysParamMapper;

    @Override
    public SysParam getSysParam(String key) {
        return sysParamMapper.selectByParamKey(key);
    }

    @Override
    public Result<IPage<SysParam>> listPage(String name, Integer pageNo, Integer pageSize) {
        Page<SysParam> page = new Page<>(pageNo, pageSize);
        IPage<SysParam> list = sysParamMapper.listPage(page, name);
        return Result.ok(list);
    }

    @Override
    public Result<SysParam> getById(Serializable id) {
        SysParam sysParam = sysParamMapper.selectById(id);
        return Result.ok(sysParam);
    }

    @Override
    public Result add(SysParam sysParam) {
        sysParamMapper.insert(sysParam);
        return Result.ok();
    }

    @Override
    public Result updateById(SysParam sysParam) {
        sysParamMapper.updateById(sysParam);
        return Result.ok();
    }

    @Override
    public Result deleteByIds(Set<Integer> ids) {
        for (Integer id : ids) {
            sysParamMapper.deleteById(id);
        }
        return Result.ok();
    }

}
